//
//  JMTextField.m
//  jiMuOperate
//
//  Created by 胡梅方 on 16/4/21.
//  Copyright © 2016年 jinXinFengLi. All rights reserved.
//

#import "JMTextField.h"

@implementation JMTextField
- (BOOL)resignFirstResponder
{
    [self setupTextFeild:self];
    return [super resignFirstResponder];
}

+ (JMTextField *)createTextFieldWithFrame:(CGRect)frame Font:(CGFloat)font Placeholder:(NSString *)placeHolder SecureTextEntry:(BOOL)isOpen TextColor:color
{
    return [[self alloc] initWithFrame:frame Font:font Placeholder:placeHolder SecureTextEntry:isOpen TextColor:color];
}

- (JMTextField *)initWithFrame:(CGRect)frame Font:(CGFloat)font Placeholder:(NSString *)placeHolder SecureTextEntry:(BOOL)isOpen TextColor:color
{
    JMTextField* textField=[[JMTextField alloc]initWithFrame:frame];
    textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:placeHolder attributes:@{NSForegroundColorAttributeName:[UIColor grayColor]}];
    
    textField.font=[UIFont systemFontOfSize:font];
    textField.textAlignment=YES;
    //    textField.placeholder = placeHolder;
    textField.textAlignment = NSTextAlignmentLeft;
    textField.tintColor=color;
    textField.textColor= color;
    
    textField.secureTextEntry=isOpen;
    textField.borderStyle = UITextBorderStyleNone;
    textField.keyboardType = UIKeyboardTypeDefault;
    textField.clearsOnBeginEditing=YES;
    
    return  textField;
}

//- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
//{
//
//    return [super textFieldShouldBeginEditing:textField];
//}

- (void)setupTextFeild:(UITextField *)textField
{
    if (textField.text.length == 0 ||[textField.text isEqualToString:self.fristText]) {
        //        textField.text = @"";
        //        textField.text = self.fristText;
        textField.textColor = [UIColor grayColor];
        self.clearsOnBeginEditing=YES;
    }else{
        textField.textColor = [UIColor blackColor];
        textField.clearsOnBeginEditing=NO;
    }
}



- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    [self setupTextFeild:textField];
    
    return YES;
}


@end
